Ext.define('BEST.controller.MainController', {
	extend : 'Ext.app.Controller',
	views : ['main.Bottom','main.West','main.Top','main.Center','main.Layout'],
	stores : [],
	models : [],
	init : function() {
		this.control({
			'top button#themeChange' : { //设置主题
				click : function(btn,eOpts){
					this.setTheme(btn);
				}
			},
			'top button#themeChange menu menucheckitem' : { //设置主题
				checkchange : function(item){
					this.changeTheme(item);
				}
			},
			'top button#logout' : { //登出
				click : function(btn,eOpts){
					this.logout(btn);
				}
			}
		});
   },
   setTheme : function(btn){
   		var me=this;
		var extTheme = Ext.util.Cookies.get('extTheme');//获取当前主题
		var items = btn.menu.items.items;
		Ext.each(items,function(item){
			if(item.css == extTheme){
				item.setChecked(true);
				return;
			}
		});
	},
	
	/**
	 * 更换主题
	 * */
	changeTheme : function(item){
		var linkid = 'extTheme';
		var link = Ext.getDom(linkid);//获取CSS引用文件
		var href = link.getAttribute('href');//获取href属性
		var lastg = href.lastIndexOf('/') + 1;//最后一个/所在的位置
		var oldcss = href.substring(lastg);//旧的主题样式
		var newcss = item.css;//新的主题样式
		if(oldcss != newcss){
			href = href.substring(0, lastg) + newcss;
			link.setAttribute('href',href);//设置href属性
			var date=new Date();
 			date.setTime(date.getTime()+24*30*3600*1000);
			Ext.util.Cookies.set(linkid,newcss,date);//保存到cookie中
		}
	},
	/**
	 * logout
	 */
	logout:function(btn){
		Ext.Ajax.request({
		    url: mainServer+'/logout.jsop',
		    timeout: 60000,
		     success: function(response){
			     window.location.href=mainServer+'/logout.htm';
			  }
		});
	}

});